
$(function() {
    var images = $('img[lazy_src]');
    var lazyLoading = function() {
        var viewW = window.outerWidth;
        var viewH = window.outerHeight;
        var winW = document.documentElement.clientWidth;
        var winH = document.documentElement.clientHeight;
        var docW = $(document).width();
        var docH = $(document).height();
        var scrollTop = $(window).scrollTop();
        var scrollLeft = $(window).scrollLeft();
/*
        console.log("viewW=" + viewW 
            + "; viewH=" + viewH 
            + "; winW=" + winW 
            + "; winH=" + winH 
            + "; docW=" + docW 
            + "; docH=" + docH 
            + "; scrollTop=" + scrollTop 
            + "; scrollLeft=" + scrollLeft 
            );
*/
        var len = images.length;
        for (var i=0; i<len; i++) {
            var img = images[i];
            var imgTop = img.offsetTop;
            var imgLeft = img.offsetLeft;
            if (img.getAttribute('lazy_src') && imgTop <= (scrollTop + winH)) {
                img.width = document.documentElement.clientWidth;
                img.height = 'auto';
                img.src = img.getAttribute('lazy_src');
                console.log('lazy_src:' + img.getAttribute('lazy_src') 
                    + '; src:' + img.src);
                img.removeAttribute('lazy_src');
                break;
            }
        }
    };
    $(window).bind("scroll", lazyLoading);
    if (images.length > 0) {
        var img = images[0];
	    img.width = document.documentElement.clientWidth;
	    img.height = 'auto';
	    img.src = img.getAttribute('lazy_src');
    }
	lazyLoading();
});
